%% @doc templerl のテスト
%%
-module(t_parallel).
-import(templ, [init/0,dismiss/0,process/1,process/2,process/3]).

-include_lib("eunit/include/eunit.hrl").

process_test() ->
	init(),
	Pid0 = spawn(fun() -> test_svr() end),
	Pid1 = spawn(fun() -> test_svr() end),
	Pid2 = spawn(fun() -> test_svr() end),
	Pid3 = spawn(fun() -> test_svr() end),
	Pid4 = spawn(fun() -> test_svr() end),
	Pid5 = spawn(fun() -> test_svr() end),
	Pid6 = spawn(fun() -> test_svr() end),
	Pid7 = spawn(fun() -> test_svr() end),
	Pid8 = spawn(fun() -> test_svr() end),
	Pid9 = spawn(fun() -> test_svr() end),
	?assert(join(Pid0)), 
	?assert(join(Pid1)), 
	?assert(join(Pid2)), 
	?assert(join(Pid3)), 
	?assert(join(Pid4)), 
	?assert(join(Pid5)), 
	?assert(join(Pid6)), 
	?assert(join(Pid7)), 
	?assert(join(Pid8)), 
	?assert(join(Pid9)).


join(Pid) ->
	Pid ! self(),
	receive
		ack -> true
	after 1000 -> false
	end.

test_svr() ->
	?assertMatch("string", 
				 process("\{string.module\}", 
						 [{"string",[{"module",string}, {"substr",substr}]}])),
	?assertMatch("ge", 
				 process("\{string.module:string.substr (\"hoge\", 3)\}", 
						 [{"string",[{"module",string}, {"substr",substr}]}])),
	?assertMatch("hello joe", 
				 process(process("{greetings}", 
								 [{"greetings", "hello {name}"}]), [{"name", "joe"}])),

	receive From -> From ! ack end.
